﻿/*********************************************************************
 版权所有: 版权所有(C) 2010 ,熙软研发部
 模块编号:  ContactGroupBO
 作    者:范徐超
 编写日期:2010-3-6
 审    核:
 审核日期:
 描    述:ContactGroupBO 通讯录联系人组  业务逻辑类
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/

using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using Cisoft.Cisoft3G.Model;

namespace Cisoft.Cisoft3G.BLL
{
    /// <summary>
    /// 业务逻辑类ContactGroupMO 的摘要说明。
    /// </summary>
    public class ContactGroupBO
    {
        private readonly Cisoft.Cisoft3G.DAL.ContactGroupDO dal = new Cisoft.Cisoft3G.DAL.ContactGroupDO();
        public ContactGroupBO()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int CG_ContactGroupID)
        {
            return dal.Exists(CG_ContactGroupID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Cisoft.Cisoft3G.Model.ContactGroupMO model)
        {
            dal.Add(model);
        }



        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Cisoft.Cisoft3G.Model.ContactGroupMO model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int CG_ContactGroupID)
        {

            dal.Delete(CG_ContactGroupID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cisoft.Cisoft3G.Model.ContactGroupMO GetModel(int CG_ContactGroupID)
        {

            return dal.GetModel(CG_ContactGroupID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cisoft.Cisoft3G.Model.ContactGroupMO GetModel(string strWhere)
        {
            return dal.GetModel(strWhere);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public Cisoft.Cisoft3G.Model.ContactGroupMO GetModelByCache(int CG_ContactGroupID)
        {

            string CacheKey = "ContactGroupMOModel-" + CG_ContactGroupID;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(CG_ContactGroupID);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Cisoft.Cisoft3G.Model.ContactGroupMO)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Cisoft.Cisoft3G.Model.ContactGroupMO> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Cisoft.Cisoft3G.Model.ContactGroupMO> DataTableToList(DataTable dt)
        {
            List<Cisoft.Cisoft3G.Model.ContactGroupMO> modelList = new List<Cisoft.Cisoft3G.Model.ContactGroupMO>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Cisoft.Cisoft3G.Model.ContactGroupMO model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Cisoft.Cisoft3G.Model.ContactGroupMO();
                    if (dt.Rows[n]["CG_ContactGroupID"].ToString() != "")
                    {
                        model.CG_ContactGroupID = int.Parse(dt.Rows[n]["CG_ContactGroupID"].ToString());
                    }
                    model.CG_GroupName = dt.Rows[n]["CG_GroupName"].ToString();
                    if (dt.Rows[n]["CG_ParentID"].ToString() != "")
                    {
                        model.CG_ParentID = int.Parse(dt.Rows[n]["CG_ParentID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

